/*
 * @(#) EvaResultAction.java Sep 30, 2011
 *
 * Copyright (c) 2011, Strong Technology. All Rights Reserved.
 * Strong Technology. CONFIDENTIAL
 */
package cn.strong.gweva.statistic.presentation.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jxls.transformer.XLSTransformer;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import cn.strong.gweva.common.business.entity.BaseExcelExportEntity;
import cn.strong.gweva.common.business.entity.PagerEntity;
import cn.strong.gweva.common.business.entity.db.JxkhResultEntity;
import cn.strong.gweva.common.presentation.action.AjaxBaseAction;
import cn.strong.gweva.common.util.StringUtil;
import cn.strong.gweva.statistic.business.entity.EvaResultEntity;
import cn.strong.gweva.statistic.business.entity.EvaResultSearchEntity;
import cn.strong.gweva.statistic.business.service.EvaResultService;


/**
 * 考核结果Action.
 * 
 * @author jincong
 * @version 1.0
 * @since Sep 30, 2011
 */
public class EvaResultAction extends AjaxBaseAction
{

	/** serialVersionUID */
	private static final long serialVersionUID = -4874968963182068039L;

	/** 考核结果Service */
	private EvaResultService evaResultService;

	/** 考核结果查询Entity */
	private EvaResultSearchEntity evaResultSearchEntity;

	/** 考核结果（分页） */
	private PagerEntity pagerEntity;

	/** 考核结果ID */
	private Integer resultId;

	/** 考核结果Entity */
	private EvaResultEntity evaResultEntity;

	/**
	 * 考核结果查询.
	 * 
	 * @return
	 */
	public String list()
	{

		try
		{
			this.pagerEntity = this.evaResultService.searchEvaResultPage(this.pagerEntity,
					this.evaResultSearchEntity);

			if (this.pagerEntity.getResultList() != null && this.pagerEntity.getResultList().size() > 0)
			{
				for (Object o : this.pagerEntity.getResultList())
				{
					EvaResultEntity entity = (EvaResultEntity) o;
					entity.setRemark(StringUtil.replaceAll(entity.getRemark(), "\r\n", "<br/>"));
				}
			}
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return LIST;
	}

	/**
	 * 考核结果导出.
	 */
	@SuppressWarnings("unchecked")
	public void export()
	{

		try
		{

			// 考核结果列表查询
			List<EvaResultEntity> list = this.evaResultService
					.searchEvaResultList(this.evaResultSearchEntity);

			Map bean = new HashMap();
			bean.put("data", list);

			BaseExcelExportEntity entity = new BaseExcelExportEntity();
			entity.setDownloadFileName("考核结果");
			entity.setTitle("考核结果");
			XLSTransformer transform = new XLSTransformer();
			// 读bean、写excel文件
			HSSFWorkbook book = transform.transformXLS(getClass().getClassLoader()
					.getResourceAsStream("cn/strong/gweva/excel/EvaResultExportTpl.xls"), bean);
			// 对EXCEL工作簿做其他处理
			process(entity, book);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * 修改工作人员初始化.
	 * 
	 * @return
	 */
	public String modify()
	{
		try
		{

			// this.worker = this.workerService.searchWorkerById(this.worker);
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return MODIFY;
	}

	/**
	 * 删除考核结果.
	 * 
	 * @return
	 */
	public String delete()
	{
		try
		{

			JxkhResultEntity jxkhResultEntity = new JxkhResultEntity();
			jxkhResultEntity.setResultId(this.resultId);
			this.evaResultService.delete(jxkhResultEntity);

			this.pagerEntity = this.evaResultService.searchEvaResultPage(this.pagerEntity,
					this.evaResultSearchEntity);
		}
		catch (Exception e)
		{
			return processException(e);
		}
		return LIST;
	}

	/**
	 * 设定考核结果Service.
	 * 
	 * @param evaResultService 考核结果Service
	 */
	public void setEvaResultService(EvaResultService evaResultService)
	{
		this.evaResultService = evaResultService;
	}

	/**
	 * 设定考核结果查询Entity.
	 * 
	 * @param evaResultSearchEntity 考核结果查询Entity
	 */
	public void setEvaResultSearchEntity(EvaResultSearchEntity evaResultSearchEntity)
	{
		this.evaResultSearchEntity = evaResultSearchEntity;
	}

	/**
	 * 获取考核结果查询Entity.
	 * 
	 * @return 考核结果查询Entity
	 */
	public EvaResultSearchEntity getEvaResultSearchEntity()
	{
		return this.evaResultSearchEntity;
	}

	/**
	 * 考核结果（分页）.
	 * 
	 * @param pagerEntity 考核结果（分页）
	 */
	public void setPagerEntity(PagerEntity pagerEntity)
	{
		this.pagerEntity = pagerEntity;
	}

	/**
	 * 考核结果（分页）.
	 * 
	 * @return 考核结果（分页）
	 */
	public PagerEntity getPagerEntity()
	{
		return this.pagerEntity;
	}

	/**
	 * 设定考核结果ID.
	 * 
	 * @param resultId 考核结果ID
	 */
	public void setResultId(Integer resultId)
	{
		this.resultId = resultId;
	}

	/**
	 * 获取考核结果ID.
	 * 
	 * @return 考核结果ID
	 */
	public Integer getResultId()
	{
		return this.resultId;
	}
}
